/**
 * 
 */
package com.google.code.netz.wfe.events;

import java.util.EventObject;

/**
 * Represents a typed event. Motivation behind this is that related events can
 * belong to a <b>class</b> of events.
 * <p>
 * For instance, we can <em>classify</em> the following <em>types</em> of Login
 * events.
 * <ul>
 * <li>User login/Session started</li>
 * <li>User logout/Session terminated</li>
 * <li>Session timeout/User logout</li>
 * </ul>
 * 
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @since 1.0F
 * @version $Id: TypedEvent.java 258 2008-11-29 06:23:51Z rahul.thakur.xdev $
 */
public abstract class TypedEvent<S> extends EventObject {

	/**
     * 
     */
	private static final long serialVersionUID = 355932175278726050L;

	/**
	 * The type of event.
	 */
	private IEventType type;

	/**
	 * @param source
	 */
	public TypedEvent(S source) {
		super(source);
	}

	/**
	 * @param source
	 * @param type
	 */
	public TypedEvent(S source, IEventType type) {
		super(source);
		this.type = type;
	}

	/**
	 * @return the type
	 */
	public IEventType getType() {
		return type;
	}

	/**
	 * Returns the appropriate source that generated this event.
	 */
	@Override
	public S getSource() {
		return (S) super.getSource();
	}

	/**
	 * Returns a {@link String} representation for this Event instance.
	 */
	@Override
	public String toString() {
		return "Event: " + this.getClass().getName() + ", Type: " + getType().asString() + ", Source: "
				+ getSource().getClass().getName();
	}

}
